package com.bocai.grainshop.product.web;


import com.bocai.grainshop.product.entity.CategoryEntity;
import com.bocai.grainshop.product.service.CategoryService;
import com.bocai.grainshop.product.vo.Catalogs2Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;



import java.util.List;
import java.util.Map;

@Slf4j
@Controller
public class indexController {

    @Autowired
    private CategoryService categoryService;

    /**
     * @Author: SunJinbo
     * @Description  主页跳转
     * @Param [model]
     * @return java.lang.String
     * @Data Created in 2022/4/1 15:02
     */
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        List<CategoryEntity> categoryEntities = categoryService.queryFristCategory();
        model.addAttribute("mydata",categoryEntities);
        return "index";
    }

    /**
     * @Author: SunJinbo
     * @Description  获取三级分类
     * @Param []
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @Data Created in 2022/4/1 15:06
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catalogs2Vo>> getCatagoryJson(){
        Map<String, List<Catalogs2Vo>> map = categoryService.getCatalogJson();
        return map;
    }

}
